//package com.example.nacosprovider.Config;//package com.example.nacosprovider.Config;
//
//import com.alibaba.fastjson.parser.ParserConfig;
//import com.alibaba.fastjson.support.config.FastJsonConfig;
//import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
//import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.data.redis.serializer.RedisSerializer;
//import org.springframework.data.redis.serializer.StringRedisSerializer;
//
//import java.nio.charset.StandardCharsets;
//
//@Configuration
//public class RedisConfig {
//    @Bean
//    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
//        // 使用 FastJsonRedisSerializer 来序列化和反序列化redis 的 value的值
//        FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<>(Object.class);
//        ParserConfig.getGlobalInstance().addAccept("com.muzz");
//        FastJsonConfig fastJsonConfig = new FastJsonConfig();
//        fastJsonConfig.setCharset(StandardCharsets.UTF_8);
//        serializer.setFastJsonConfig(fastJsonConfig);
//        return serializer;
//
//        //或者使用GenericFastJsonRedisSerializer进行序列化
//        //return new GenericFastJsonRedisSerializer();
//    }
//
//    @Bean
//    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
//        RedisTemplate<String, Object> template = new RedisTemplate<>();
//        template.setConnectionFactory(redisConnectionFactory);
//        FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<>(Object.class);
//        // value值的序列化采用fastJsonRedisSerializer
//        template.setValueSerializer(serializer);
//        template.setHashValueSerializer(serializer);
//        // key的序列化采用StringRedisSerializer
//        template.setKeySerializer(redisKeySerializer());
//        template.setHashKeySerializer(redisKeySerializer());
//        template.setConnectionFactory(redisConnectionFactory);//
//        template.setDefaultSerializer(redisKeySerializer());
//        template.afterPropertiesSet();
//        return template;
//    }
//    @Bean
//    public RedisSerializer<?> redisKeySerializer() {
//        return new StringRedisSerializer();
//    }
//
//    @Bean
//    public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory){
//        StringRedisTemplate template = new StringRedisTemplate();
//        template.setConnectionFactory(redisConnectionFactory);
//        return template;
//    }
//
//}
